<?php

class Fan_Widget_FanController extends Engine_Content_Widget_Abstract
{
  protected $_childCount;
	
  public function indexAction()
  {
      // This Code I added to call $viewer in index.tpl page ($this->view->viewer)
  $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
    if( !Engine_Api::_()->core()->hasSubject() ) {
      return $this->setNoRender();
    }

    // Get subject and check auth
    $this->view->subject = $subject = Engine_Api::_()->core()->getSubject();
    if( !$subject->authorization()->isAllowed($viewer, 'view') ) {
        return $this->setNoRender();
    }
    
    $table = Engine_Api::_()->getDbtable('fans','fan');
    $select = $table->select()->where('resource_id = ?',$subject->getIdentity());
    $this->view->fans = $fans = $table->fetchAll($select);
 
    
//////////////////////////////////////////////////////////////////////////////    
    
    /*This COde is for Not showing WIDGET on Tab bar :  IF nobody has Selected or be a fan or not wrote any blog : then it will not show on tab bar */
    $this->view->paginator = $paginator = Zend_Paginator::factory($select);

    // Set item count per page and current page number
    $paginator->setItemCountPerPage($this->_getParam('itemCountPerPage', 10));
    $paginator->setCurrentPageNumber($this->_getParam('fan', 1));

    // Do not render if nothing to show
    if( $paginator->getTotalItemCount() <= 0 ) {
      return $this->setNoRender();
    }
    
      // Add count to title if configured
    if( $this->_getParam('titleCount', false) && $paginator->getTotalItemCount() > 0 ) {
      $this->_childCount = $paginator->getTotalItemCount();
    }
    
//////////////////////////////////////////////////////////////////////////////////    
    }
    

  public function getChildCount()
  {
    return $this->_childCount;
  }
    
 }

